package com.ymatou.iapi.sellerproduct.testcase;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.sellerproduct.service.GetActivityPreviewProductListV2Call;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.LiveCallService;
import com.ymttest.business.service.SellerProductCallService;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;

public class Ts_GetActivityPreviewProductListV2 {
	private static String sellerName = EnvSetup.getData("productsellername");
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("App-直播预览");
	}

	@Before
	public void caseUp() {
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(new GetActivityPreviewProductListV2Call().getOpurl());
	}
	
	
	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetActivityPreviewProductListV2_001() {
		Logger.start(true, "App-直播预览");
		try{
			//1 create live
			JSONObject liveBean = LiveCallService.createLiveInProgress(sellerName,sellerId);
			Logger.verifyEquals( 200,liveBean.getInt("Code"), "响应报文-返回码");
			
			int liveId = liveBean.getJSONObject("Data").getInt("ActivityId");
			
			//2 add new product
			 JSONObject productBean = SellerProductCallService.addNewProductNotOnSale(sellerId,sellerName,null);
			 String productId =	productBean.getJSONObject("Data").getString("ProductID");
			
			 
			//3 add product to live
	    	JSONObject addProductInLiveBean = SellerProductCallService.addProductInLive(sellerId,liveId,productId);
			Logger.verifyEquals( 200,addProductInLiveBean.getInt("Code"), "响应报文-返回码");
			
			
			//App-直播预览
			JSONObject ret = new GetActivityPreviewProductListV2Call().callAndGetReturnData(MapUtil.hashMap("UserId", sellerId, "ActivityId", liveId));
			
			Logger.verifyEquals(200,ret.getInt("Code"), "响应报文-返回码");
			Logger.verifyEquals(productId,ret.getJSONObject("Data").getJSONArray("Products").getJSONObject(0).getString("ProductId"), "响应报文-商品id");
			Logger.verifyEquals(liveId,ret.getJSONObject("Data").getJSONObject("Activity").getInt("ActivityId"), "响应报文-商品id");
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
}
